package cn.mavor.day0929.SuperMarket;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

// Member class to represent a member with card number, name, and points.
class Member implements Serializable {
    private String cardNumber;
    private String name;
    private int points;
    private String password;

    public Member(String cardNumber, String name, String password) {
        this.cardNumber = cardNumber;
        this.name = name;
        this.points = 0; // Start with zero points
        this.password = password;
    }

    // Getters and Setters
    public String getCardNumber() { return cardNumber; }
    public String getName() { return name; }
    public int getPoints() { return points; }
    public void setPoints(int points) { this.points = points; }
    public String getPassword() { return password; }
    public void setPassword(String password) { this.password = password; }

    // Add points
    public void addPoints(int points) {
        this.points += points;
    }

    // Redeem points
    public boolean redeemPoints(int points) {
        if (this.points >= points) {
            this.points -= points;
            return true;
        } else {
            return false;
        }
    }
}

// Supermarket class to manage members.
class Supermarket implements Serializable {
    private String name;
    private String address;
    private Map<String, Member> members;

    public Supermarket(String name, String address) {
        this.name = name;
        this.address = address;
        this.members = new HashMap<>();
    }

    // Methods for managing members
    public void addMember(Member member) {
        members.put(member.getCardNumber(), member);
    }

    public Member findMemberByCardNumber(String cardNumber) {
        return members.get(cardNumber);
    }

    // Other methods can be added here...
}